# ----------------------------------------------------------------------
#  Project: War Time Military Service Can Affect Partisan Preferences
#  Last updated: November 8,2022
#  Purpose: Prepare INES data for analyses
#  Outputs: data/ines_77_2019.csv"
#  Machine: Chagai's macbook pro
# ----------------------------------------------------------------------


# load packages---------
library("tidyverse")
library("readstata13")


# Clean INES Data-------
##2019-----
ines_2019 <- read.dta13("raw_data/2019.dta")


# create partisanship indicators

ines_2019 <- ines_2019 %>% 
  mutate(.,
         right_wing = case_when(
           v111 %in% 1:3 ~ 1,
           v111 %in% 4:7 ~ 0),
         center = ifelse(v111 == 4, 1, 0),
         left_wing = case_when(
           v111 %in% 1:4 ~ 0,
           v111 %in% 5:7 ~ 1),
         ideology_7 = ifelse(v111 <8, v111, NA),
         election_year = 2019)


# Filter sample to include only jews
ines_2019 <- ines_2019 %>% 
  filter(.,
         v149 == 1)


## Create rhs and lhs variables
ines_2019 <- ines_2019 %>% 
  mutate(edu = case_when(
    educ < 3 ~ "Less then HS",
    educ %in% 4:5 ~ "HS",
    educ %in% 5:8 ~ "Academic"),
    relig = case_when(
      v144 == 1 ~ "V. Relig",
      v144 == 2 ~ "Relig",
      v144 %in% 3:4 ~ "Traditional",
      v144  == 5 ~ "Secular"),
    ashkenazi = ifelse(v135 == 1, 1, 0),
    spending = case_when(
      v139 < 6 ~ v139 ),# 1.alot נקךם׳ average, 2. a bit 3. average 4. above 5. a lot above 
    Sex = ifelse(gender == 1, "male", "female"),
    labor_sec = NA,
    labor_econ = NA,
    rooms_hh = ifelse(v140<98, v140, NA),
    ppl_hh = ifelse(v141<98, v141, NA),
    situation_bad = ifelse(v6<98, v6,NA),
    gov_preform = ifelse(v7<98, v7,NA),
    gov_preform = 5-gov_preform,
    security_salience = ifelse(v8_code_1 %in% c(1:9),1,0),
    econ_salience = ifelse(v8_code_1 %in% c(15:20),1,0),
    peace_salience = ifelse(v8_code_1 %in% c(12:14),1,0),
    violence_threat = ifelse(v14 < 5, v14, NA),
    violence_threat = 5-violence_threat,
    war_over_peace = case_when(
      v13 == 1 ~ 0,
      v13 == 2 ~ 1),
    aliya_after_73 = ifelse(v134 >1973,1,0),
    aliya_after_73 = ifelse(v134 == 9999,NA,aliya_after_73),
    running_var = age-64,
    running_var_67 = age-70,
    undecide = ifelse(v104 == 97,1,0),
    no_vote = ifelse(v104 == 94,1,0),
    vote_likud = ifelse(v104 == 1,1,0),
    vote_labor = ifelse(v104 == 3,1,0))



ines_2019 <- ines_2019 %>% 
  select(.,c(age, MIDGAM, right_wing:vote_labor)) %>% 
  rename(.,
         week = MIDGAM)



##2015---
### Read data
ines_2015 <- read.dta13("raw_data/2015.dta")


# create indicator of self reported partisanship

ines_2015 <- ines_2015 %>% 
  mutate(.,
         right_wing = case_when(
           v103 %in% 1:3 ~ 1,
           v103 %in% 4:7 ~ 0),
         left_wing = case_when(
           v103 %in% 1:4 ~ 0,
           v103 %in% 5:7 ~ 1),
         center = ifelse(v103 == 4, 1, 0),
         ideology_7 = ifelse(v103 <8, v103, NA),
         election_year = 2015)


# Filter sample to include only jews
ines_2015 <- ines_2015 %>% 
  filter(.,
         v148 == 1)

# Create RHS and lhs variables
ines_2015 <- ines_2015 %>% 
  mutate(.,
         ashkenazi = ifelse(v120 == 1,1,0),
         edu = case_when(
           v128 < 3 ~ "Less then HS",
           v128 %in% 4:5 ~ "HS",
           v128 %in% 5:8 ~ "Academic"
         ),
         relig = case_when(
           v139 == 1 ~ "V. Relig",
           v139 == 2 ~ "Relig",
           v139 %in% 3:4 ~ "Traditional",
           v139  == 5 ~ "Secular"),
         spending = case_when(
           v134 <6 ~ v134),
         Sex = ifelse(sex == 1, "male", "female"),
         labor_sec = ifelse(v58 == 1,1,0),
         labor_econ = ifelse(v57 == 1,1,0),
         rooms_hh = ifelse(v135<99, v135, NA),
         ppl_hh = ifelse(v136<99, v136, NA),
         situation_bad = ifelse(v6<9, v6,NA),
         gov_preform = ifelse(v7<9, v7,NA),
         gov_preform = 5-gov_preform,
         security_salience = ifelse(v8 %in% c(1:10),1,0),
         econ_salience = ifelse(v8 %in% c(18:24),1,0),
         peace_salience = ifelse(v8 %in% c(15:17),1,0),
         violence_threat = ifelse(v15 < 5, v15, NA),
         violence_threat = 5-violence_threat,
         war_over_peace = case_when(
           v15 == 1 ~ 0,
           v15 == 2 ~ 1),
         aliya_after_73 = ifelse(v118 >1973,1,0),
         aliya_after_73 = ifelse(v118 == 9999,NA,aliya_after_73),
         running_var = age-60,
         running_var_67 = age-66,
         undecide = ifelse(v92 == 97,1,0),
         no_vote = ifelse(v92 == 94,1,0),
         vote_likud = ifelse(v92 == 1,1,0),
         vote_labor = ifelse(v92 == 2,1,0))



ines_2015 <- ines_2015 %>% 
  select(.,c(date, age, midgam, right_wing:vote_labor)) %>% 
  rename(.,
         week = midgam)


ines_master <- bind_rows(ines_2019, ines_2015)


##2013-----
### Read data
ines_2013 <- read.dta13("raw_data/2013.dta")


ines_2013 <- ines_2013 %>% 
  mutate(.,
         ideology_7 = case_when(
           v88 == "1. right-wing" ~ 1,
           v88 == 2 ~ 2,
           v88 == 3 ~ 3,
           v88 == 4 ~ 4,
           v88 == 5 ~ 5,
           v88 == 6 ~ 6,
           v88 == "7. left -wing" ~ 7),
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 1:4 ~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7 == 4, 1, 0),
         election_year = 2013)



# Filter sample to include only jews
ines_2013 <- ines_2013 %>% 
  filter(.,
         v153 == "1. jewish")


## create rhs and lhs variables
ines_2013$v137 <- as.numeric(ines_2013$v137)

ines_2013 <- ines_2013 %>% 
  mutate(.,
         ashkenazi = ifelse(grepl("europe", v133), 1, 0),
         edu = case_when(
           v137 < 3 ~ "Less then HS",
           v137 %in% 4:5 ~ "HS",
           v137 %in% 5:8 ~ "Academic"
         ),
         relig = case_when(
           v150 == "4.  hareidi (for arabs: very religious)" ~ "V. Relig",
           v150 == "3.  religious" ~ "Relig",
           v150 == "2.  traditional" ~ "Traditional",
           v150  == "1.  secular" ~ "Secular"
         ),
         spending = NA,
         Sex = ifelse(sex == "1.  male", "male", "female"),
         labor_sec = ifelse(v50 == "3.  sheli yachimovich",1,0),
         labor_econ = ifelse(v48 == "3.  sheli yachimovich",1,0),
         rooms_hh = ifelse(v146<99, v146, NA),
         ppl_hh = ifelse(v147<99, v147, NA),
         situation_bad = case_when(
           v6 == "1. very good" ~ 1,
           v6 == "2. good" ~ 2,
           v6 == "3. so so" ~ 3, 
           v6 == "4. not good" ~ 4,
           v6 == "5. bad" ~ 5),
         gov_preform = case_when(
           v7 == "4. handling them very badly" ~ 1,
           v7 == "3. handling them in a bad way" ~ 2,
           v7 == "2. handling them in a good way" ~ 3,
           v7 == "1. handling them in a very good way" ~ 4),
         important = as.numeric(v8),
         security_salience = ifelse(important %in% c(1:10),1,0),
         econ_salience = ifelse(important %in% c(18:24),1,0),
         peace_salience = ifelse(important %in% c(15:17),1,0),
         violence_threat = case_when(
           v16 == "4.  not at all worried" ~ 1,
           v16 == "3.  not worried" ~ 2,
           v16 == "2.  worried" ~ 3,
           v16 == "1.  very worried" ~ 4),
         war_over_peace = case_when(
           v15 == "1.  concentrate on peace talks" ~ 0,
           v15 == "2.  increase military strength" ~ 1),
         aliya_after_73 = ifelse(v134 >1973,1,0),
         aliya_after_73 = ifelse(v134 == 9999,NA,aliya_after_73),
         running_var = age - 58,
         running_var_67 = age-64,
         undecide = ifelse(v101 == "97. have not decided/debating",1,0),
         no_vote = ifelse(v101 == "98. not intending to vote",1,0),
         vote_likud = ifelse(v101 == "1. likud - israel beiteinu",1, 0),
         vote_labor = ifelse(v101 == "2. labor",1, 0))

names(ines_2013)
ines_2013 <- ines_2013 %>% 
  select(.,c(date, age, week, ideology_7:vote_labor)) 


### Combine master with 2013
ines_master <- bind_rows(ines_2013, ines_master)
# Note that in 2013 spending is NA



##2009-----
ines_2009 <- read.dta13("raw_data/2009.dta") 
ines_2009 <- ines_2009 %>% 
  mutate(.,
         year = 2009)


# create indicator of self reported partisanship
`%notin%` <- Negate(`%in%`)
ines_2009 <- ines_2009 %>% 
  mutate(.,
         ideology_7 = case_when(
           v135 == "1 right" ~ 1,
           v135 == 2 ~ 2,
           v135 == 3 ~ 3,
           v135 == 4 ~ 4,
           v135 == 5 ~ 5,
           v135 == 6 ~ 6,
           v135 == "7 left" ~ 7),
         ideology_10 = case_when(
           v90 == "10 right" ~ 1,
           v90 == 9 ~ 1,
           v90 == 8 ~ 2,
           v90 == 7 ~ 2,
           v90 == 6 ~ 3,
           v90 == 5 ~ 4,
           v90 == 4 ~ 5,
           v90 == 3 ~ 6,
           v90 == 2 ~ 6,
           v90 == 1 ~ 7,
           v90 == "0 left" ~ 7),
         ideology_5 = case_when(
           v134 == "5. right" ~ 1,
           v134 == "4. moderate right" ~ 2,
           v134 == "3. center" ~ 4,
           v134 == "2. moderate left" ~ 6,
           v134 == "1. left" ~ 7),
         ideology_7 = ifelse(is.na(ideology_7), ideology_10, ideology_7), 
         ideology_7 = ifelse(is.na(ideology_7), ideology_5, ideology_7), 
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 1:4 ~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7 == 4,1,0),
         election_year = 2009)


# Filter sample to include only jews
ines_2009 <- ines_2009 %>% 
  filter(.,
         v195 == "1. jewish")


## Create rhs and lhs variables
ines_2009$v191 <- as.numeric(ines_2009$v191)
ines_2009 <- ines_2009 %>% rowwise() %>%  
  mutate(.,
         age = age_1,
         ashkenazi = ifelse(grepl("europe", v179a), 1, 0),
         edu = case_when(
           v191 < 3 ~ "Less then HS",
           v191 == 3 ~ "HS",
           v191 %in% 4:6 ~ "Academic"
         ),
         relig = case_when(
           v190 == "4. haredi" ~ "V. Relig",
           v190 == "3. religious" ~ "Relig",
           v190 == "2. traditional" ~ "Traditional",
           v190  == "1. secular" ~ "Secular"
         ),
         spending = case_when(
           grepl("1", v184) ~ 5,
           grepl("2", v184) ~ 4,
           grepl("3", v184) ~ 3,
           grepl("4", v184) ~ 2,
           grepl("5", v184) ~ 1
         ),
         Sex = case_when(
           sex_1 == "1. male" ~ "male",
           sex_2 == "1. male" ~ "male",
           sex_1 == "2. female" ~ "female",
           sex_2 == "2. female" ~ "female"
         ),
         labor_sec = ifelse(v74a == "3. ehud barak",1,0),
         labor_econ = ifelse(v72a == "3. ehud barak",1,0),
         rooms_hh = v186,
         ppl_hh = v187,
         situation_bad = case_when(
           v6 == "1 very good" ~ 1,
           v6 == "2  good" ~ 2,
           v6 == "3 so so" ~ 3, 
           v6 == "4 not good" ~ 4,
           v6 == "5 bad" ~ 5),
         gov_preform = case_when(
           v7 == "4. it handles them in a not at all good way" ~ 1,
           v7 == "3.  it handles them in a not so good way" ~ 2,
           v7 == "2. it handles them in a good way" ~ 3,
           v7 == "1. it handles them in a very good way" ~ 4),
         important = as.numeric(v8),
         security_salience = ifelse(important %in% c(1:10),1,0),
         econ_salience = ifelse(important %in% c(17:19),1,0),
         peace_salience = ifelse(important %in% c(14:16),1,0),
         violence_threat = case_when(
           v21 == "4. not worried at all" ~ 1,
           v21 == "3. not worried" ~ 2,
           v21 == "2. worried" ~ 3,
           v21 == "1. very worried" ~ 4),
         war_over_peace = case_when(
           v20 == "1. focus on the peace process" ~ 0,
           v20 == "2. building military strength" ~ 1),
         aliya_after_73 = ifelse(v177 >1973,1,0),
         running_var = age-54,
         running_var_67 = age-60,
         undecide = ifelse(v154 == "97. undecided/debating",1,0),
         no_vote = ifelse(v154 == "98. do not intend to vote",1,0),
         vote_likud = ifelse(v154 == "2. likud",1, 0),
         vote_labor = ifelse(v154 == "3. labor",1, 0))


# Select relevant variables
ines_2009 <- ines_2009 %>% 
  select(.,c(age, ideology_7:vote_labor)) 

ines_master <- bind_rows(ines_2009, ines_master)


##2006-----
### Read data

ines_2006 <- read.dta13("raw_data/2006.dta") 
ines_2006 <- ines_2006 %>% 
  mutate(.,
         year = 2006)

# create indicator of self reported partisanship
# Note in this wave it is a left right scale where right is higher values

ines_2006 <- ines_2006 %>% 
  mutate(.,
         ideology_7 = case_when(
           b7 == 1 ~ 1,
           b7 == 2 ~ 2,
           b7 == 3 ~ 2,
           b7 == 4 ~ 3,
           b7 == 5 ~ 4,
           b7 == 6 ~ 4,
           b7 == 7 ~ 5,
           b7 == 8 ~ 6,
           b7 == 9 ~ 6,
           b7 == 10 ~ 7),
         right_wing = case_when(
           ideology_7 %in%  1:3~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in%  1:4~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7 == 4, 1, 0),
         election_year = 2006)



# Filter sample to include only jews
ines_2006 <- ines_2006 %>% 
  filter(.,
         d33 == "jewish")


## Create polarization variables
# Create variables for rhs and lhs
ines_2006 <- ines_2006 %>% 
  mutate(.,
         age = d31,
         edu = case_when(
           c75 < 12 ~ "Less then HS",
           c75 == 12  ~ "HS",
           c75 >12 ~ "Academic"
         ),
         relig = case_when(
           c88 == "haredi" ~ "V. Relig",
           c88 == "religious" ~ "Relig",
           c88 == "traditional" ~ "Traditional",
           c88  == "secular" ~ "Secular"
         ),
         ashkenazi = ifelse(grepl("europe", origin),1,0),
         spending = case_when(
           c80 == "much less" ~ 1,
           c80 == "a little less" ~ 2,
           c80 == "about the average" ~ 3,
           c80 == "a little more" ~ 4,
           c80 == "much more" ~ 5),
         Sex = d36,
         labor_sec = ifelse(a82 == "avoda leaders",1,0),
         labor_econ = ifelse(a78 == "avoda leaders",1,0),
         rooms_hh = c82,
         ppl_hh = c84,
         situation_bad = case_when(
           a6 == "very good" ~ 1,
           a6 == "good" ~ 2,
           a6 == "so so" ~ 3, 
           a6 == "not good" ~ 4,
           a6 == "bad" ~ 5),
         gov_preform = case_when(
           a7 == "very badly" ~ 1,
           a7 == "bad way" ~ 2,
           a7 == "good way" ~ 3,
           a7 == "very good way" ~ 4),
         important = as.numeric(a8),
         security_salience = ifelse(important %in% c(1:10),1,0),
         econ_salience = ifelse(important %in% c(17:19),1,0),
         peace_salience = ifelse(important %in% c(14:16),1,0),
         violence_threat = case_when(
           a24 == "not worried at all" ~ 1,
           a24 == "not worried" ~ 2,
           a24 == "worried" ~ 3,
           a24 == "very worried" ~ 4),
         war_over_peace = case_when(
           a23 == "no one" ~ 0,
           a23 == "peace talks and military might" ~ 0,
           a23 == "having peace talks" ~ 0,
           a23 == "strengthening its military might" ~ 1),
         aliya_after_73 = ifelse(c60 >73,1,0),
         running_var = d31-51,
         running_var_67 = age-57,
         undecide = ifelse(b73 == "undecided",1,0),
         no_vote = ifelse(b73 == "do not intend to vote",1,0),
         vote_likud = ifelse(b73 == "likud",1,0),
         vote_labor = ifelse(b73 == "avoda",1,0))


# Merge data
ines_master <- bind_rows(ines_2006, ines_master)

#2003-----
### Read data

ines_2003 <- read.dta13("raw_data/2003.dta") 
ines_2003 <- ines_2003 %>% 
  mutate(.,
         year = 2003) 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_2003 <- ines_2003 %>% 
  mutate(.,
         ideology_7 = a49,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 1:4 ~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7 == 4, 1, 0),
         election_year = 2003)



# Filter sample to include only jews
ines_2003 <- ines_2003 %>% 
  filter(.,
         jew == "jew")


## variables for rhs and lhs
ines_2003$age <- ines_2003$b74
ines_2003 <- ines_2003 %>% 
  mutate(.,
         edu = case_when(
           b82 < 12 ~ "Less then HS",
           b82 == 12 ~ "HS",
           b82 > 12  ~ "Academic"
         ),
         relig = case_when(
           b91 == "haredi" ~ "V. Relig",
           b91 == "religious" ~ "Relig",
           b91 == "traditional" ~ "Traditional",
           b91  == "secular" ~ "Secular"
         ),
         ashkenazi = case_when(
           b77 == 3 ~ 1,
           b77 == 4 ~ 1,
           b77 < 3 ~ 0,
           b77 == 4 ~ 1,
           b77 %in% 5:12 ~ 0,
           b77 %in% 13:14 ~ 1,
           b77 > 14 ~ 0
         ),
         spending = case_when(
           b85 == "much below average" ~ 1,
           b85 == "below average" ~ 2,
           b85 == "average" ~ 3,
           b85 == "a little above average" ~ 4,
           b85 == "much more than average" ~ 5
         ),
         Sex = b92,
         labor_sec = ifelse(a48 == "labor leaders",1,0),
         labor_econ = ifelse(a47 == "avoda leaders",1,0),
         rooms_hh = b87,
         ppl_hh = b88,
         situation_bad = case_when(
           a6 == "very good" ~ 1,
           a6 == "good" ~ 2,
           a6 == "neither good nor bad" ~ 3, 
           a6 == "bad" ~ 4,
           a6 == "very bad" ~ 5),
         gov_preform = case_when(
           a7 == "not well at all" ~ 1,
           a7 == "not very well" ~ 2,
           a7 == "well" ~ 3,
           a7 == "very well" ~ 4),
         important = as.numeric(a8),
         security_salience = ifelse(important %in% c(1:6),1,0),
         econ_salience = ifelse(important %in% c(8:11),1,0),
         peace_salience = ifelse(important ==7,1,0),
         violence_threat = case_when(
           a24 == "not at all worried" ~ 1,
           a24 == "not worried" ~ 2,
           a24 == "worried" ~ 3,
           a24 == "very worried" ~ 4),
         war_over_peace = case_when(
           a19 == "concentrate on peace talks" ~ 0,
           a19 == "increase military strength " ~ 1),
         aliya_after_73 = ifelse(b79 >73,1,0),
         running_var = b74-48,
         running_var_67 = age-54,
         undecide = ifelse(b63 == "no decision",1,0),
         no_vote = ifelse(b63 == "will not vote",1,0),
         vote_likud = ifelse(b63 == "likud",1,0),
         vote_labor = ifelse(b63 == "labor",1,0))

ines_2003 <- ines_2003 %>% 
  select(.,c(age, ideology_7:vote_labor)) 


### Combine data
ines_master <- bind_rows(ines_master, ines_2003)


##2001---------

### Read data

ines_2001 <- read.dta13("raw_data/2001.dta") 
ines_2001 <- ines_2001 %>% 
  mutate(.,
         year = 2001)


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_2001 <- ines_2001 %>% 
  mutate(.,
         ideology_7 = case_when(
           a49 == 1 ~ 1,
           a49 == 2 ~ 2,
           a49 == 3 ~ 2,
           a49 == 4 ~ 3,
           a49 == 5 ~ 4,
           a49 == 6 ~ 4,
           a49 == 7 ~ 5,
           a49 == 8 ~ 6,
           a49 == 9 ~ 6,
           a49 == 10 ~ 7),
         right_wing = case_when(
           ideology_7 %in% 1:3~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 1:4~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7==4,1,0),
         election_year = 2001)



# Filter sample to include only jews
ines_2001 <- ines_2001 %>% 
  filter(.,
         b55 != "arabic")


## rhs and lhs variables
ines_2001$age <- ines_2001$b24
ines_2001 <- ines_2001 %>% 
  mutate(.,
         edu = case_when(
           b38 < 12 ~ "Less then HS",
           b38 == 12 ~ "HS",
           b38 > 12 ~ "Academic"
         ),
         relig = case_when(
           b27 == "haredi" ~ "V. Relig",
           b27 == "religious" ~ "Relig",
           b27 == "traditional" ~ "Traditional",
           b27  == "secular" ~ "Secular"
         ),
         ashkenazi = ifelse(grepl("europe", b33), 1,0),
         spending = case_when(
           b41 == "much below" ~ 1,
           b41 == "somewhat below" ~ 2,
           b41 == "average" ~ 3,
           b41 == "somewhat above" ~ 4,
           b41 == "more than average" ~ 5),
         Sex = b47,
         labor_sec = ifelse(a65 == "barak",1,0),
         labor_econ = ifelse(a64 == "barak",1,0),
         rooms_hh = b42,
         ppl_hh = b44,
         situation_bad = case_when(
           a6 == "very good" ~ 1,
           a6 == "good" ~ 2,
           a6 == "so so" ~ 3, 
           a6 == "not good" ~ 4,
           a6 == "bad" ~ 5),
         gov_preform = case_when(
           a7 == "not good" ~ 1,
           a7 == "not so good" ~ 2,
           a7 == "good" ~ 3,
           a7 == "very good" ~ 4),
         important = as.numeric(a8),
         security_salience = ifelse(important == 1,1,0),
         econ_salience = ifelse(important ==2,1,0),
         peace_salience = ifelse(important ==3,1,0),
         violence_threat = case_when(
           a24 == "not at all worried" ~ 1,
           a24 == "not worried" ~ 2,
           a24 == "worried" ~ 3,
           a24 == "very worried" ~ 4),
         war_over_peace = NA,
         aliya_after_73 = ifelse(b35 >73,1,0),
         running_var = age - 46,
         running_var_67 = age-52,
         undecide = ifelse(b14 == "undecided",1,0),
         no_vote = ifelse(b14 == "will not vote",1,0),
         vote_likud = ifelse(b14 == "likud",1,0),
         vote_labor = ifelse(b14 == "one israel",1,0))


ines_2001 <- ines_2001 %>% 
  select(.,c(age, ideology_7:vote_labor)) 
ines_master <- bind_rows(ines_master, ines_2001)


## 1999-----------
### Read data
ines_1999 <- read.dta13("raw_data/1999-1.dta") 
# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1999 <- ines_1999 %>% 
  mutate(.,
         ideology_7 = i19,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 1:4 ~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1999)



# Omit non Jewish respondents
ines_1999 <- filter(ines_1999,
                    c40 <79)


## variables for lhs and rhs
ines_1999$age <- ines_1999$c20
ines_1999 <- ines_1999 %>% 
  mutate(.,
         edu = case_when(
           c28 < 12 ~ "Less then HS",
           c28 == 12 ~ "HS",
           c28 > 12 ~ "Academic"
         ),
         relig = case_when(
           c38 == "orthodox" ~ "V. Relig",
           c38 == "religious" ~ "Relig",
           c38 == "traditional" ~ "Traditional",
           c38  == "secular" ~ "Secular"
         ),
         ashkenazi = ifelse(grepl("europe", c26), 1,0),
         spending = case_when(
           c30 == "much below average" ~ 1,
           c30 == "below average" ~ 2,
           c30 == "average" ~ 3,
           c30 == "more than average" ~ 4,
           c30 == "much above average" ~ 5),
         Sex = c39,
         labor_sec = ifelse(i5 == "barak",1,0),
         labor_econ = ifelse(i4 == "barak",1,0),
         rooms_hh = c34,
         ppl_hh = c35,
         situation_bad = case_when(
           v3 == "very good" ~ 1,
           v3 == "good" ~ 2,
           v3 == "so-so" ~ 3, 
           v3 == "not good" ~ 4,
           v3 == "bad" ~ 5),
         gov_preform = case_when(
           v4 == "not well at all" ~ 1,
           v4 == "not so well" ~ 2,
           v4 == "well" ~ 3,
           v4 == "very well" ~ 4),
         important = v5,
         security_salience = ifelse(important == 1,1,0),
         econ_salience = ifelse(important ==2,1,0),
         peace_salience = ifelse(important ==3,1,0),
         violence_threat = case_when(
           v25 == "not worried at all" ~ 1,
           v25 == "not worried" ~ 2,
           v25 == "worried" ~ 3,
           v25 == "very worried" ~ 4),
         war_over_peace = case_when(
           v24 == "increase its military might"  ~ 1,
           v24 == "concentrate on peace talks" ~ 0),
         aliya_after_73 = ifelse(c27 >73,1,0),
         running_var = age - 44,
         running_var_67 = age-50,
         undecide = ifelse(c12 == 99,1,0),
         no_vote = ifelse(c12 == 98,1,0),
         vote_likud = ifelse(c12 == 2,1,0),
         vote_labor = ifelse(c12 == 1,1,0))

ines_1999 <- select(ines_1999,
                    ideology_7:vote_labor)





ines_master <- bind_rows(ines_master, ines_1999)


# 1999b-----
### Read data

ines_1999b <- read.dta13("raw_data/1999-2.dta") 


# No Indicator allowing to filter our arabs




# The survey does not include partisanship indicators

ines_1999b$age <- ines_1999b$d37
ines_1999b <- ines_1999b %>% 
  mutate(.,
         edu = case_when(
           d36 < 12 ~ "Less then HS",
           d36 == 12 ~ "HS",
           d36 > 12 ~ "Academic"),
         relig = NA,
         ashkenazi = NA,
         spending = NA,
         knowledge = NA,
         turnout = NA,
         politc_conv = NA,
         Sex = d35,
         labor_sec = NA,
         labor_econ = NA,
         rooms_hh = NA,
         ppl_hh = NA,
         situation_bad = NA,
         gov_preform = NA,
         important = d2,
         security_salience = ifelse(important == "security and terrorism in general",1,0),
         econ_salience = ifelse(important =="economy",1,0),
         peace_salience = ifelse(important =="peace process",1,0),
         violence_threat = NA,
         war_over_peace = NA,
         aliya_after_73 = NA,
         running_var = age - 44,
         running_var_67 = age-50,
         undecide = NA,
         no_vote = ifelse(d9 == "did not vote",1,0),
         vote_likud = ifelse(d9 == "likud",1,0),
         vote_labor = ifelse(d9 == "one israel",1,0),
         election_year = 1999.1)







ines_master <- bind_rows(ines_master, ines_1999b)




##1996------------------
### Read data
ines_1996 <- read.dta13("raw_data/1996j.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1996 <- ines_1996 %>% 
  mutate(.,
         ideology_7 = c69,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 1:4 ~ 0,
           ideology_7 %in% 5:7 ~ 1),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1996)





# The survey does not include partisanship indicators

ines_1996$age <- ines_1996$ccc57
ines_1996 <- ines_1996 %>% 
  mutate(.,
         edu = case_when(
           ccc63 < 12 ~ "Less then HS",
           ccc63 == 12 ~ "HS",
           ccc63 > 12 ~ "Academic"),
         relig = case_when(
           ccc70 == "do not keep the jewish tradition at all" ~ "Secular",
           ccc70 == "a little" ~ "Traditional",
           ccc70 == "much" ~ "Relig",
           ccc70 == "thoroughly" ~ "V. Relig"),
         ashkenazi = ifelse(sephashk == "ashkenazi",1,0),
         spending = case_when(
           ccc74 == "much below average" ~ 1, 
           ccc74 == "below average" ~ 2,
           ccc74 == "average" ~ 3,
           ccc74 == "more than average" ~ 4,
           ccc74 == "much above average" ~ 5),
         Sex = ccc56,
         labor_sec = ifelse(cc24 == "labor",1,0),
         labor_econ = ifelse(cc23 == "labor",1,0),
         rooms_hh = ccc65,
         ppl_hh = ccc67,
         situation_bad = case_when(
           c6 == "very good" ~ 1,
           c6 == "good" ~ 2,
           c6 == "so-so" ~ 3, 
           c6 == "not good" ~ 4,
           c6 == "bad" ~ 5,
           c6 == "very bad" ~ 5),
         gov_preform = case_when(
           c7 == "badly" ~ 1,
           c7 == "not so well" ~ 2,
           c7 == "well" ~ 3,
           c7 == "very well" ~ 4),
         important = as.numeric(c8),
         security_salience = ifelse(important == 1,1,0),
         econ_salience = ifelse(important == 2,1,0),
         peace_salience = ifelse(important ==3,1,0),
         violence_threat = case_when(
           c42 == "not worried at all" ~ 1,
           c42 == "not worried" ~ 2,
           c42 == "worried" ~ 3,
           c42 == "very worried" ~ 4),
         war_over_peace = case_when(
           c41 == "increase its military might"  ~ 1,
           c41 == "concentrate on peace talks" ~ 0),
         aliya_after_73 = ifelse(ccc61 >73,1,0),
         running_var = age - 41,
         running_var_67 = age-47,
         undecide = ifelse(ccc23 == "not decided yet",1,0),
         no_vote = ifelse(ccc23 == "will not vote",1,0),
         vote_likud = ifelse(ccc23 == "likud-tzomet-gesher",1,0),
         vote_labor = ifelse(ccc23 == "labor",1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)






ines_master <- bind_rows(ines_master, ines_1996)






## 1992-----------------------------------------------------------

### Read data

ines_1992 <- read.dta13("raw_data/1992.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1992 <- ines_1992 %>% 
  mutate(.,
         ideology_7 = a110,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 5:7 ~ 1,
           ideology_7 %in% 1:4 ~ 0),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1992)





# The survey does not include partisanship indicators

ines_1992$age <- ines_1992$i61
ines_1992 <- ines_1992 %>% 
  mutate(.,
         edu = case_when(
           i62 < 12 ~ "Less then HS",
           i62 == 12 ~ "HS",
           i62 > 12 ~ "Academic"),
         relig = case_when(
           i50 == "does not observe at all" ~ "Secular",
           i50 == "observes to a small extent" ~ "Traditional",
           i50 == "observes to a great extent" ~ "Relig",
           i50 == "observes completely" ~ "V. Relig"),
         ashkenazi = ifelse(i51 == 1,1,0),
         spending = case_when(
           i65 == "way below average" ~ 1, 
           i65 == "somewhat below average" ~ 2,
           i65 == "average" ~ 3,
           i65 == "somewhat above average" ~ 4,
           i65 == "way above average" ~ 5),
         Sex = i67,
         labor_sec = ifelse(a58 == "labor",1,0),
         labor_econ = ifelse(a57 == 1,1,0),
         rooms_hh = ifelse(i63>0.3,i63,NA),
         ppl_hh = i64,
         situation_bad = ifelse(a2<6,a2,NA),
         gov_preform = case_when(
           a3 == "bad" ~ 1,
           a3 == "not so good" ~ 2,
           a3 == "good" ~ 3,
           a3 == "very good" ~ 4),
         important = as.numeric(a7),
         security_salience = ifelse(important == 2,1,0),
         econ_salience = ifelse(important == 1,1,0),
         peace_salience = ifelse(important ==5,1,0),
         violence_threat = case_when(
           a48 == "not concerned at all" ~ 1,
           a48 == "not concerned" ~ 2,
           a48 == "concerned" ~ 3,
           a48 == "highly concerned" ~ 4),
         war_over_peace = ifelse(a18 == 2, 1, 0),
         aliya_after_73 = ifelse(i53 >73,1,0),
         running_var = age - 37,
         running_var_67 = age-43,
         undecide = ifelse(i41 == 16,1,0),
         no_vote = ifelse(i41 == 17,1,0),
         vote_likud = ifelse(i41 == 2,1,0),
         vote_labor = ifelse(i41 == 1,1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1992)


ines_master <- bind_rows(ines_master, ines_1992)


##1988--------------
### Read data

ines_1988 <- read.dta13("raw_data/1988_N=873.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1988 <- ines_1988 %>% 
  mutate(.,
         ideology_7 = f125,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 5:7 ~ 1,
           ideology_7 %in% 1:4 ~ 0),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1988)





# The survey does not include partisanship indicators

ines_1988$age <- ines_1988$g78
ines_1988 <- ines_1988 %>% 
  mutate(.,
         edu = case_when(
           g80 < 12 ~ "Less then HS",
           g80 == 12 ~ "HS",
           g80 > 12 ~ "Academic"),
         relig = case_when(
           g66 == "do not observe at all, totally free" ~ "Secular",
           g66 == "observe some of religious laws" ~ "Traditional",
           g66 == "observe most of religious laws" ~ "Relig",
           g66 == "observe all religious laws to the letter" ~ "V. Relig"),
         ashkenazi = ifelse(g67 == "ashkenazi",1,0),
         spending = case_when(
           g85 == "well below average" ~ 1, 
           g85 == "somewhat below average" ~ 2,
           g85 == "as average" ~ 3,
           g85 == "somewhat above average" ~ 4,
           g85 == "well above average" ~ 5),
         Sex = g104,
         labor_sec = ifelse(f72 == "ma'arah's team",1,0),
         labor_econ = ifelse(f71 == 1,1,0),
         rooms_hh = g83,
         ppl_hh = g84,
         situation_bad = as.numeric(f6),
         gov_preform = case_when(
           f7 == "not well at all" ~ 1,
           f7 == "not so well" ~ 2,
           f7 == "well" ~ 3,
           f7 == "very well" ~ 4),
         important = as.numeric(f11),
         security_salience = ifelse(important %in% c(1:5),1,0),
         econ_salience = ifelse(important %in% c(8:10),1,0),
         peace_salience = ifelse(important == 7,1,0),
         violence_threat = NA,
         war_over_peace = ifelse(f23 == "increase military power", 1, 0),
         aliya_after_73 = case_when(
           g70 == "israeli born" ~ 0,
           g70 == "before 1948" ~ 0,
           g70 == "1948-1954" ~ 0,
           g70 == "1955-1960" ~ 0,
           g70 == "1961-1966" ~ 0,
           g70 == "1967-1972" ~ 0,
           g70 == "1973-1977" ~ 1,
           g70 == "1978-1983" ~ 1,
           g70 == "1984+" ~ 1),
         running_var = age - 33,
         running_var_67 = age-39,
         undecide = ifelse(g22 == "did not decide yet",1,0),
         no_vote = ifelse(g22 == "no intention to vote",1,0),
         vote_likud = ifelse(g22 == "likud",1,0),
         vote_labor = ifelse(g22 == "labor",1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1988)





ines_master <- bind_rows(ines_master, ines_1988)




## 1988B------------------------------------------------------
### Read data
ines_1988b <- read.dta13("raw_data/1988_Panel_N=416.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1988b <- ines_1988b %>% 
  mutate(.,
         ideology_7 = b126,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 5:7 ~ 1,
           ideology_7 %in% 1:4 ~ 0),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1988.1)





# The survey does not include partisanship indicators

ines_1988b$age <- ines_1988b$c57
ines_1988b <- ines_1988b %>% 
  mutate(.,
         edu = case_when(
           a99 < 12 ~ "Less then HS",
           a99 == 12 ~ "HS",
           a99 > 12 ~ "Academic"),
         relig = case_when(
           c46 == "do not observe at all, totally free" ~ "Secular",
           c46 == "observe some of religious laws" ~ "Traditional",
           c46 == "observe most of religious laws" ~ "Relig",
           c46 == "observe all religious laws to the letter" ~ "V. Relig"),
         ashkenazi = ifelse(c47 == "ashkenazi",1,0),
         spending = case_when(
           c62 == "a lot under average" ~ 1, 
           c62 == "a little under average" ~ 2,
           c62 == "the same as the average" ~ 3,
           c62 == "a little over average" ~ 4,
           c62 == "a lot over average" ~ 5),
         knowledge = NA,
         turnout = NA,
         politc_conv = NA,
         Sex = a119,
         labor_sec = ifelse(b69 == "ma'arah's team",1,0),
         labor_econ = ifelse(b68 == "ma'arah's team",1,0),
         rooms_hh = c60,
         ppl_hh = c61,
         situation_bad = as.numeric(b2),
         gov_preform = case_when(
           b3 == "not well at all" ~ 1,
           b3 == "not so well" ~ 2,
           b3 == "well" ~ 3,
           b3 == "very well" ~ 4),
         important = NA,
         security_salience = NA,
         econ_salience = NA,
         peace_salience = NA,
         violence_threat = NA,
         war_over_peace = ifelse(v59 == "to increase its military power", 1, 0),
         aliya_after_73 = case_when(
           c49 == "israeli born" ~ 0,
           c49 == "before 1948" ~ 0,
           c49 == "1948-1954" ~ 0,
           c49 == "1955-1960" ~ 0,
           c49 == "1961-1966" ~ 0,
           c49 == "1967-1972" ~ 0,
           c49 == "1973-1977" ~ 1,
           c49 == "1978-1983" ~ 1,
           c49 == "1984+" ~ 1),
         running_var = age - 33,
         running_var_67 = age-39,
         undecide = ifelse(a63 == "has not decided yet",1,0),
         no_vote = ifelse(a63 == "would not vote",1,0),
         vote_likud = ifelse(a63 == "likud (herut+liberalim++la'am+ometz+tami)",1,0),
         vote_labor = ifelse(a63 == "labour (maarach) (labour+yahad)",1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1988)





ines_master <- bind_rows(ines_master, ines_1988b)





## 1984------------------
### Read data

ines_1984 <- read.dta13("raw_data/1984.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1984 <- ines_1984 %>% 
  mutate(.,
         ideology_7 = v43,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 5:7 ~ 1,
           ideology_7 %in% 1:4 ~ 0),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1984)





# The survey does not include partisanship indicators

ines_1984$age <- ines_1984$a54
ines_1984 <- ines_1984 %>% 
  mutate(.,
         edu = case_when(
           a53 == 12 ~ "HS",
           a53 == "full university education" ~ "Academic"),
         edu = ifelse(is.na(edu), "Less then HS", edu),
         relig = case_when(
           a48 == "does not observe them at all, secular" ~ "Secular",
           a48 == "observes to a small extent" ~ "Traditional",
           a48 == "observes to a great extent" ~ "Relig",
           a48 == "observes completely" ~ "V. Relig"),
         ashkenazi = ifelse(a47 == "ashkenazi",1,0),
         spending = case_when(
           a55 == "way below average" ~ 1, 
           a55 == "somewhat below average" ~ 2,
           a55 == "average" ~ 3,
           a55 == "somewhat above average" ~ 4,
           a55 == "way above average" ~ 5),
         knowledge = NA,
         turnout = NA,
         politc_conv = NA,
         Sex = case_when(
           a58 == 1 ~ "female",
           a58 == 2 ~ "male"),
         labor_sec = ifelse(v24 == "alignment",1,0),
         labor_econ = ifelse(v23 == "alignment",1,0),
         rooms_hh = NA,
         ppl_hh = NA,
         situation_bad = as.numeric(v2),
         gov_preform = v3,
         important = as.numeric(v4),
         security_salience = ifelse(important == 2,1,0),
         econ_salience = ifelse(important == 3,1,0),
         peace_salience = ifelse(important == 5,1,0),
         violence_threat = NA,
         war_over_peace = NA,
         aliya_after_73 = case_when(
           a50 == "born in israel" ~ 0,
           a50 == "before 1948" ~ 0,
           a50 == "1948-1954" ~ 0,
           a50 == "1955-1960" ~ 0,
           a50 == "1961-1966" ~ 0,
           a50 == "1967-1972" ~ 0,
           a50 == "1973-1977" ~ 1,
           a50 == "1978-1979" ~ 1,
           a50 == "1980+" ~ 1),
         running_var = age - 29,
         running_var_67 = age-35,
         undecide = ifelse(a41 == 19,1,0),
         no_vote = ifelse(a41 == 20,1,0),
         vote_likud = ifelse(a41 == 2,1,0),
         vote_labor = ifelse(a41 == 1,1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1984)





ines_master <- bind_rows(ines_master, ines_1984)
table(ines_master$election_year, ines_master$ideology_7)






##1981-------------


### Read data

ines_1981 <- read.dta13("raw_data/1981-1.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1981 <- ines_1981 %>% 
  mutate(.,
         ideology_7 = v116,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 5:7 ~ 1,
           ideology_7 %in% 1:4 ~ 0),
         center = ifelse(v116==4,1,0),
         election_year = 1981)





# The survey does not include partisanship indicators

ines_1981$age <- ines_1981$v134
ines_1981 <- ines_1981 %>% 
  mutate(.,
         edu = case_when(
           v136 == 12 ~ "HS",
           v136 == "university degree" ~ "Academic"),
         edu = ifelse(is.na(edu), "Less then HS", edu),
         relig = case_when(
           v143 == "secular" ~ "Secular",
           v143 == "to some extent" ~ "Traditional",
           v143 == "to a great extent" ~ "Relig",
           v143 == "observes them strictly" ~ "V. Relig"),
         ashkenazi = ifelse(grepl("europe", v137), 1, 0),
         spending = NA, # Provides raw spending rather than subjective evaluation
         Sex = case_when(
           v135 == 1 ~ "male",
           v135 == 2 ~ "female"),
         labor_sec = case_when(
           v4 == "security" & v6 == 1 ~ 1,
           v4 == "security" & v6 != 1 ~ 0),
         labor_econ = case_when(
           v4 == "economy" & v6 == 1 ~ 1,
           v4 == "economy" & v6 != 1 ~ 0),
         rooms_hh = v144,
         ppl_hh = v145,
         situation_bad = ifelse(v2 <6,v2,NA),
         gov_preform = ifelse(v3 <6,5-v3,NA),
         important = as.numeric(v4),
         security_salience = ifelse(important==2,1,0),
         econ_salience = ifelse(important ==3,1,0),
         peace_salience = ifelse(important == 5,1,0),
         violence_threat = NA,
         war_over_peace = NA,
         aliya_after_73 = case_when(
           v138 == "born in israel" ~ 0,
           v138 == "before 1948" ~ 0,
           v138 == "1948-1954" ~ 0,
           v138 == "1955-1960" ~ 0,
           v138 == "1961-1966" ~ 0,
           v138 == "1967-1972" ~ 0,
           v138 == "1973-1977" ~ 1,
           v138 == "1978-1978" ~ 1,
           v138 == "1980+" ~ 1),
         running_var = age - 26,
         running_var_67 = age-32,
         undecide = ifelse(v122 == "&",1,0),
         no_vote = ifelse(v122 == "&",1,0),
         vote_likud = ifelse(v122 == 2,1,0),
         vote_labor = ifelse(v122 == 1,1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1981)





ines_master <- bind_rows(ines_master, ines_1981)
table(ines_master$election_year, ines_master$vote_labor)
names(ines_master)

### Note that the questions regarding labor security and econ in this wave are slightly different
# due to absence of the classic survey question in this wave.


##1981B-----
### Read data
ines_1981.1 <- read.dta13("raw_data/1981-2.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1981.1 <- ines_1981.1 %>% 
  mutate(.,
         ideology_7 = NA,
         right_wing = ifelse(a133 == 4,1,0),
         center = ifelse(a133==3,1,0),
         left = ifelse(a133 <3 & a133>0,1,0),
         election_year = 1981.1)





# The survey does not include partisanship indicators


ines_1981.1$age <- ines_1981.1$a151
ines_1981.1 <- ines_1981.1 %>% 
  filter(.,
         age >17) %>% 
  mutate(.,
         edu = case_when(
           a147 < 5 ~ "Less then HS",
           a147 == 6 ~ "HS",
           a147 == 7 ~ "HS",
           a147 == 8 ~ "Academic"),
         relig = case_when(
           a155 == 4 ~ "Secular",
           a155 == 3 ~ "Traditional",
           a155 == 2 ~ "Relig",
           a155 == 1 ~ "V. Relig"),
         ashkenazi = case_when(
           a157 == 3 ~ 1,
           a157 == 5 ~ 1),
         ashkenazi = ifelse(is.na(ashkenazi), 0,1),
         spending = NA, # Provides raw spending rather than subjective evaluation
         knowledge = NA,
         turnout = NA,
         politc_conv = NA,
         Sex = a146,
         labor_sec = NA,
         labor_econ = NA,
         rooms_hh = a148,
         ppl_hh = a149,
         situation_bad = ifelse(a2 >0, a2, NA),
         gov_preform = ifelse(a3>0,5-a3,NA),
         important = a4,
         security_salience = ifelse(important == 1,1,0),
         econ_salience = ifelse(important == 2,1,0),
         peace_salience = ifelse(important == 4,1,0),
         violence_threat = NA,
         war_over_peace = NA,
         aliya_after_73 = ifelse(a158>8,1,0),
         running_var = age - 26,
         running_var_67 = age-32,
         undecide = ifelse(a142 == 17,1,0),
         no_vote = ifelse(a142 == 18,1,0),
         vote_likud = ifelse(a142 == 1,1,0),
         vote_labor = case_when(
           a142 == 4 ~ 1,
           a142 == 7 ~ 1),
         vote_labor = ifelse(is.na(vote_labor), 0,vote_labor)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1981.1)





ines_master <- bind_rows(ines_master, ines_1981.1)




##1981C-------
### Read data

ines_1981.2 <- read.dta13("raw_data/1981-3.dta") 


# create indicator of self reported partisanship
# Note in this wave it is a right left  scale where left is higher values

ines_1981.2 <- ines_1981.2 %>% 
  mutate(.,
         ideology_7 = b80,
         right_wing = case_when(
           ideology_7 %in% 1:3 ~ 1,
           ideology_7 %in% 4:7 ~ 0),
         left_wing = case_when(
           ideology_7 %in% 5:7 ~ 1,
           ideology_7 %in% 1:4 ~ 0),
         center = ifelse(ideology_7==4,1,0),
         election_year = 1981.2)





# The survey does not include partisanship indicators
ines_1981.2$b149 <- as.numeric(ines_1981.2$b149)
ines_1981.2$b151 <- as.numeric(ines_1981.2$b151)
ines_1981.2$age <- ines_1981.2$b137
ines_1981.2 <- ines_1981.2 %>% 
  mutate(.,
         edu = case_when(
           b139 ==  12 ~ "HS",
           b139 == "13+, without academic degree" ~ "HS",
           b139 == "full university education" ~ "Academic"),
         edu = ifelse(is.na(edu), "Less then HS", edu),
         relig = case_when(
           b145 == "does not observe them at all, secular" ~ "Secular",
           b145 == "observes some of the traditions" ~ "Traditional",
           b145 == "observes them to a great extent" ~ "Relig",
           b145 == "observes them strictly" ~ "V. Relig"),
         ashkenazi = ifelse(grepl("europe", b140), 1, 0),
         spending = NA, # Provides raw spending rather than subjective evaluation
         knowledge = NA,
         turnout = NA,
         politc_conv = NA,
         Sex = case_when(
           b138 == 1 ~ "male",
           b138 == 2 ~ "female"),
         labor_sec = ifelse(b14 == "haim bar-lev",1,0),
         labor_econ = ifelse(b18 == 2,1,0),
         rooms_hh = b149,
         ppl_hh = b151,
         situation_bad = ifelse(b2 >0, b2, NA),
         gov_preform = ifelse(b3<5,5-b3,NA),
         important = as.numeric(b6),
         security_salience = ifelse(important == 2,1,0),
         econ_salience = ifelse(important == 3,1,0),
         peace_salience = ifelse(important == 5,1,0),
         violence_threat = NA,
         war_over_peace = NA,
         aliya_after_73 = case_when(
           b141 == "born in israel" ~ 0,
           b141 == "before 1948" ~ 0,
           b141 == "1948-1954" ~ 0,
           b141 == "1955-1960" ~ 0,
           b141 == "1961-1966" ~ 0,
           b141 == "1967-1972" ~ 0,
           b141 == "1973-1977" ~ 1,
           b141 == "1978-1979" ~ 1,
           b141 == "1980+" ~ 1),
         running_var = age - 26,
         running_var_67 = age-32,
         undecide = ifelse(b89 == 17, 1, 0),
         no_vote = ifelse(b89 == 18,1,0),
         vote_likud = ifelse(b89 == 2,1,0),
         vote_labor = ifelse(b89 == 1,1,0)) %>% 
  dplyr::select(.,
                ideology_7:vote_labor)
names(ines_1981.2)





ines_master <- bind_rows(ines_master, ines_1981.2)


##1977-----

### Read data

ines_1977 <- read.dta13("raw_data/1977-1.dta") 


# Self reported partisanship doesnt exist




# The survey does not include partisanship indicators

ines_1977$age <- ines_1977$v116
ines_1977 <- ines_1977 %>% 
  mutate(.,
         election_year = 1977,
         edu = case_when(
           v112 < 6 ~ "Less then HS",
           v112 == 6 ~ "HS",
           v112 == 7 ~ "HS",
           v112 == 8 ~ "Academic"),
         relig = case_when(
           v120 == "not at all" ~ "Secular",
           v120 == "to a small extent" ~ "Traditional",
           v120 == "to a great extent" ~ "Relig",
           v120 == "observes them thoroughly" ~ "V. Relig"),
         ashkenazi = case_when(
           v123 == 1 ~ 0,
           v123 == 2 ~ 0,
           v123 == 3 ~ 1,
           v123 == 4 ~ 0,
           v123 == 5 ~ 1,
           v123 == 6 ~ 0),
         spending = NA, # Provides raw spending rather than subjective evaluation
         knowledge = NA,
         turnout = NA,
         politc_conv = NA,
         Sex = case_when(
           v111 == 1 ~ "male",
           v111 == 2 ~ "female"),
         labor_sec = case_when(
           v6 == "security" & v9 == "alignment" ~ 1,
           v6 == "security" & v9 != "alignment" ~ 0),
         labor_econ = case_when(
           v6 == "economy" & v9 == "alignment" ~ 1,
           v6 == "economy" & v9 != "alignment" ~ 0),
         rooms_hh = v113,
         ppl_hh = v114,
         situation_bad = case_when(
           v4 == "very good" ~ 1,
           v4 == "good" ~ 2,
           v4 == "not so good" ~ 3,
           v4 == "not good" ~ 4,
           v4 == "not good at all" ~ 5),
         gov_preform = case_when(
           v5 == "not well at all" ~ 1,
           v5 == "not so well" ~ 2,
           v5 == "it is handling them well" ~ 3,
           v5 == "it is handling them very well" ~ 4),
         important = as.numeric(v6),
         security_salience = ifelse(important == 2,1,0),
         econ_salience = ifelse(important == 3,1,0),
         peace_salience = ifelse(important == 5,1,0),
         violence_threat = NA,
         war_over_peace = NA,
         aliya_after_73 = case_when(
           v124 == "israeli born" ~ 0,
           v124 == "before 1930" ~ 0,
           v124 == "1931-1940" ~ 0,
           v124 == "1941-1947" ~ 0,
           v124 == "1948-1954" ~ 0,
           v124 == "1955-1960" ~ 0,
           v124 == "1961-1964" ~ 0,
           v124 == "1965-1967" ~ 0,
           v124 == "1968+" ~ 0), 
         running_var = age - 22,
         running_var_67 = age-28,
         undecide = ifelse(v107 == "has not decided yet", 1, 0),
         no_vote = ifelse(v107 == "will not vote for the knesset",1,0),
         vote_likud = ifelse(v107 == "likud",1,0),
         vote_labor = ifelse(v107 == "alignment",1,0)) %>% 
  dplyr::select(.,
                age:vote_labor)
names(ines_1977)

#Different format of question regarding labor competence wrt security/econ



ines_master <- bind_rows(ines_master, ines_1977)


##Write data------
# Edit Aliya indictor to set NAs as 0 (in essence what we care about are the 1 values)

ines_master <- ines_master %>% 
  mutate(.,
         aliya_after_73 = ifelse(is.na(aliya_after_73),0, aliya_after_73),
         age_in_73 = running_var+18,
         age_in_67 = running_var_67+18)

write.csv(ines_master, "data_for_analyses/ines_77_2019.csv")

